package com.daigou.tools;

import java.util.Random;

public class RandomPassword {
	public static char[] getChar() {
		char[] passwordLit = new char[62];
		char fword = 'A';
		char mword = 'a';
		char bword = '0';
		for (int i = 0; i < 62; i++) {
			if (i < 26) {
				passwordLit[i] = fword;
				fword++;
			} else if (i < 52) {
				passwordLit[i] = mword;
				mword++;
			} else {
				passwordLit[i] = bword;
				bword++;
			}// 方法的抽取，按功能
		}
		return passwordLit;
	}

	public static void main(String[] args) {
		System.out.println(generateRandomPassword(6));
	}
	
	public static String generateRandomPassword(int size){
		char[] r = getChar();
		Random rr = new Random();
		char[] pw = new char[size];
		for (int i = 0; i < pw.length; i++) {
			int num = rr.nextInt(62);
			pw[i] = r[num];
		}
		return String.valueOf(pw);
	}
	
}
